package com.atguigu.gmall.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/9/3 11:08
 */
public class IkUtil {
    public static Set<String> analyzer(String keyword){
        HashSet<String> set = new HashSet<>();
        
        // 内存流
        StringReader reader = new StringReader(keyword);
        IKSegmenter segmenter = new IKSegmenter(reader, true);
        try {
            Lexeme next = segmenter.next();
            while (next != null){
                String key = next.getLexemeText();
                set.add(key);
                next = segmenter.next();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        return set;
    
    }
    
    public static void main(String[] args) {
        System.out.println(analyzer("我是中国人"));
    
    }
}
